package concurency.vehicletracker.publishing;

import java.util.*;
import java.util.concurrent.*;

public class PublishingVehicleTracker {
	private final Map<String, SafePoint> locations;
	private final Map<String, SafePoint> unmodifiableMap;

	public PublishingVehicleTracker(Map<String, SafePoint> locations) {
		this.locations = new ConcurrentHashMap<String, SafePoint>(
				locations);
		this.unmodifiableMap = Collections.unmodifiableMap(this.locations);
	}

	public Map<String, SafePoint> getLocations() {
		return unmodifiableMap;
	}

	public SafePoint getLocation(String id) {
		SafePoint loc = locations.get(id);
		if (loc == null){
			throw new IllegalArgumentException("ID: " + id + " not found");
		}
		return loc;
	}

	public void setLocation(String id, int x, int y) {
		if (!locations.containsKey(id)){
			throw new IllegalArgumentException("ID: " + id + " not found");
		}
		locations.get(id).set(x, y);
	}
}
